package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Usertype;
import com.restaurant.service.UsertypeService;

public class UsertypeServiceImpl implements UsertypeService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Usertype addOrModify( Usertype objUsertype ) {
       return ( Usertype ) hibernateTemplate.merge( objUsertype );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Usertype deleteRecord( Usertype objUsertype ) {
       hibernateTemplate.delete( objUsertype );
       return objUsertype;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Usertype modifyRecord( Usertype objUsertype ) {
       return ( Usertype ) hibernateTemplate.merge( objUsertype );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Usertype> loadAll() {
       return (List<Usertype>)hibernateTemplate.findByNamedQuery( "Usertype.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Usertype loadByPrimaryKey( Long primaryKey ) {
       return (Usertype) hibernateTemplate.get( Usertype.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Usertype deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Usertype> loadByHql(String query) {
       return ( List<Usertype> ) hibernateTemplate.find( query );
   }
}